// import { ConfigStore } from "@/interface/store/config"
import { useCallback } from "react"
import { useSelector } from "react-redux"

// import { IUseDataMappingProps } from "./types"
import { AppState } from "@/stores"

import { useLocale } from "."

export const useDataMapping = () => {
	const { allDictLists, allDictReady } = useSelector((state: AppState) => state.config)
	// console.log(allDictLists["merchantList"])
	const { newFormat } = useLocale()
	// const { value, modal, func, strictlyLabel, customDictArr } = props
	const getLabel = useCallback(
		(value: string | number, modal: string, strictlyLabel = true, customDictArr?: any[]) => {
			if (!value && value !== 0) return "-"
			const label = (customDictArr || allDictLists[modal])?.find((item: any) =>
				!isNaN(Number(value)) ? Number(item.value) === Number(value) : item.value === value
			)?.label
			return !label ? "-" : strictlyLabel ? label : newFormat({ id: label })
		},
		[allDictReady]
	)
	const getFromDic = (modal: string, strictlyLabel = true) => {
		const render = (value: string | number) => {
			return getLabel(value, modal, strictlyLabel)
		}
		return render
	}
	return { getLabel, getFromDic }
}
